﻿@using WsdShop.Model.Enum
@{
    Layout = null;
}
<style>
    .new_toLine {
        padding: 10px 0;
    }

        .new_toLine .icon {
            float: left;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            border: 1px solid #eb272a;
            color: #eb272a;
            font-size: 12px;
            text-align: center;
            line-height: 18px;
            margin-right: 10px;
        }

    .new_bzLine {
        border-top: 1px solid #f5f5f5;
        color: #a2a2a2;
        padding: 10px 0 0;
    }
</style>
<div class="w_shopcar w_submitOrder w_allorder" ng-controller="MyOrderController">
    <!--顶部菜单-->
    <ul class="w_allOrder_menu" style="position: fixed;top:0;width: 100%;left:0;z-index: 99">
        <li ng-class="{true:'w_allorder_default',false:''}[Status==0]" ng-click="show(0)"><span>全部</span></li>
        <li ng-class="{true:'w_allorder_default',false:''}[Status==1]" ng-click="show(1)"><span>待付款</span></li>
        <li ng-class="{true:'w_allorder_default',false:''}[Status==2]" ng-click="show(2)"><span>待收货</span></li>
        <li ng-class="{true:'w_allorder_default',false:''}[Status==3]" ng-click="show(3)"><span>待评价</span></li>
        <li ng-class="{true:'w_allorder_default',false:''}[Status==4]" ng-click="show(4)"><span>退货</span></li>
    </ul>
    <div style="margin-top: 55px;" class="f_a_row">
        <!--全部-->
        <div class="w_allod_change" ng-show="Status!=4">
            <div class="w_shopcar_pershop " ng-repeat="order in List">
                <div class="w_scPershop_ti">
                    <span>{{order.OrderNo}}</span>
                    <p class="w_allorder_state w_allState_red">{{order.StatusDes}}</p>
                </div>
                <div class="w_odt_procon">
                    <div ng-repeat="item in order.OrderDetailList" ng-click="$state.go('shop.orderdetail',{id:order.Id})" style="width:100%" class="clearfix">
                        <div class="w_odtpro_conleft"><img src="{{ImgHostUrl+item.ImgUrl}}" /></div>
                        <div class="w_odtpro_conright">
                            <div class="w_odtpro_name">{{item.ProductName}}</div>
                            <p class="w_submitOrder_gg">{{item.SpecName}}</p>
                            <div class="w_shopcar_more">
                                <font color="#eb272a"><small>￥</small>{{item.DiscountPrice}}</font>
                                <p class="w_submitOrder_num">X<big>{{item.ProductCount}}</big></p>
                            </div>
                        </div>
                    </div>
                    <div class="w_allod_persum">合计：<font color="#ff4242">￥{{order.ProductPrice}}</font></div>
                    <div class="w_allod_sub">
                        <a ng-show="order.PayState==@((int)OrderPayStatus.未支付)&&order.OrderState==@((int)OrderStatus.待确认)" class="w_allod_subRed" ng-click="gopay(order.Id)">去付款</a>
                        <a ng-show="order.PayState==@((int)OrderPayStatus.未支付)&&order.OrderState!=@((int)OrderStatus.已取消)" class="w_allod_subBlack" ng-click="cancelOrder(order.Id)">取消订单</a>
                        @*<a ng-show="order.OrderState==@((int)OrderStatus.已确认)&&order.SendStatus === @((int)OrderSendStatus.已发货)" ng-click="confirmOrder(order.Id)" class="w_allod_subBlack">确认收货</a>*@
                        <a ng-show="order.OrderState==@((int)OrderStatus.已收货)" ng-click="$state.go('user.addcomment',{orderId:order.Id})" class="w_allod_subBlack">去评价</a>
                        <a ng-show="order.OrderState==@((int)OrderStatus.已取消)" class="w_allod_subBlack" ng-click="delOrder(order.Id)">删除订单</a>
                        @*<a ng-show="order.IsAllowReturn" class="w_allod_subBlack" ng-click="$state.go('shop.return',{id:order.Id})">申请退货</a>*@
                    </div>
                </div>
            </div>
        </div>
        <!--全部-->

        <div class="w_allod_change" ng-show="Status==4">
            <div class="w_shopcar_pershop" ng-repeat="order in ReturnList">
                <div class="w_scPershop_ti">
                    <span>{{order.OrderNo}}</span>
                    <p class="w_allorder_state w_allState_red">{{order.SatusDes}}</p>
                </div>
                <div class="w_odt_procon">
                    <div class="w_odtpro_conleft"><img src="{{ImgHostUrl+order.orderDetail.ImgUrl}}" /></div>
                    <div class="w_odtpro_conright">
                        <div class="w_odtpro_name">{{order.orderDetail.ProductName}}</div>
                        <p class="w_submitOrder_gg">{{order.orderDetail.SpecName}}</p>
                        <div class="w_shopcar_more">
                            <font color="#eb272a"><small>￥</small>{{order.orderDetail.DiscountPrice}}</font>
                            <p class="w_submitOrder_num">X<big>{{order.orderDetail.ProductCount}}</big></p>
                        </div>
                    </div>
                    <div class="w_allod_persum" ng-show="order.ReturnType==0&&order.ReturnAmount>0">退款金额：<font color="#ff4242">￥{{order.ReturnAmount}}</font></div>
                    <div class="new_toLine">
                        <p class="icon">{{order.ReturnType==0?'退':'换'}}</p>@*<label ng-show="order.ReturnType==0&&order.ReturnResultDes!=''">{{order.ReturnResultDes}}</label>*@
                    </div>
                    <div class="new_bzLine" ng-show="order.Remark&&order.Remark.length>0">
                        客服备注：{{order.Remark}}
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script>

    App.controller('MyOrderController', [
       '$scope', '$state', '$route', '$http','$rootScope', '$stateParams',"$filter",
           function ($scope, $state, $route, $http,$rootScope,$stateParams,$filter) {
               $scope.Status = 0;
               $scope.List = [];


               var getData=function()
               {
                   layer.load(2);
                   $http.post("/UserCenter/GetMyOrder").then(function (response) {
                       layer.closeAll('loading');
                       $scope.AllList = angular.copy(response.data.data);
                       $scope.ReturnList = angular.copy(response.data.data1);
                       if ($scope.AllList != null && $scope.AllList.length > 0)
                       {
                           //待支付
                           $scope.List1 = $filter('filter')($scope.AllList, function (item) { return item.PayState === @((int)OrderPayStatus.未支付); });
                           //待收货
                           $scope.List2 = $filter('filter')($scope.AllList, function (item) { return (item.SendStatus === @((int)OrderSendStatus.已发货)|| item.SendStatus===@((int)OrderSendStatus.部分发货) )&&item.OrderState===@((int)OrderStatus.已确认) ; });
                           //待评价
                           $scope.List3 = $filter('filter')($scope.AllList, function (item) { return item.OrderState===@((int)OrderStatus.已收货) ; });
                           //已完成
                           $scope.List4 = $filter('filter')($scope.AllList, function (item) { return item.OrderState===@((int)OrderStatus.已完成) ; });

                           if($scope.Status==1)
                           {
                               $scope.List=angular.copy($scope.List1);
                           }
                           else if($scope.Status==2)
                           {
                               $scope.List=angular.copy($scope.List2);
                           }
                           else if($scope.Status==3)
                           {
                               $scope.List=angular.copy($scope.List3);
                           }
                           else if($scope.Status==4)
                           {
                               $scope.List=angular.copy($scope.List4);
                           }
                           else
                           {
                               $scope.List=angular.copy($scope.AllList);
                           }
                       }
                   });
               }

               if ($stateParams.status && $stateParams.status > 0) {
                   $scope.Status=$stateParams.status;
               }
               getData();


               $scope.show=function(status)
               {
                   $scope.Status=status;
                   if($scope.Status==1)
                   {
                       $scope.List=angular.copy($scope.List1);
                   }
                   else if($scope.Status==2)
                   {
                       $scope.List=angular.copy($scope.List2);
                   }
                   else if($scope.Status==3)
                   {
                       $scope.List=angular.copy($scope.List3);
                   }
                   else if($scope.Status==4)
                   {
                       $scope.List=angular.copy($scope.List4);
                   }
                   else
                   {
                       $scope.List=angular.copy($scope.AllList);
                   }
               }

               var tt = function () {
                   $rootScope.WxShare($rootScope.pageTitle(), '优品三悦', location.href, $rootScope.LogoUrl);
               }

               setTimeout(tt, 1000)

               $scope.cancelOrder=function(id){


                   layer.confirm('确定取消吗？', {
                       btn: ['确定', '取消'] //按钮
                   }, function () {
                       layer.load(2);
                       $http.post("/Order/CancelOrder", { id: id }).then(function (response) {
                           layer.closeAll('loading');
                           if (response.data.isSuccess) {
                               layer.msg("操作成功");
                               getData();
                           }
                           else {

                               layer.msg(response.data.msg);
                           }

                       });
                   }, function () {

                   });
               }

               $scope.delOrder=function(id){


                   layer.confirm('确定删除吗？', {
                       btn: ['确定', '取消'] //按钮
                   }, function () {
                       layer.load(2);
                       $http.post("/Order/DelOrder", { id: id }).then(function (response) {
                           layer.closeAll('loading');
                           if (response.data.isSuccess) {
                               layer.msg("操作成功");
                               getData();
                           }
                           else {

                               layer.msg(response.data.msg);
                           }

                       });
                   }, function () {

                   });
               }

               $scope.confirmOrder=function(id){


                   layer.confirm('确认收货吗？', {
                       btn: ['确定', '取消'] //按钮
                   }, function () {
                       layer.load(2);
                       $http.post("/Order/ConfirmOrder", { id: id }).then(function (response) {
                           layer.closeAll('loading');
                           if (response.data.isSuccess) {
                               layer.msg("操作成功");
                               getData();
                           }
                           else {

                               layer.msg(response.data.msg);
                           }

                       });
                   }, function () {

                   });
               }
               $scope.gopay= function (oid) {
                   window.location.href = "/OrderPayment/Index?orderId=" + oid;
               }
           }
    ]);
</script>
